/**
 * 充值管理
 */
<template>
  <div>
    <!-- 面包屑导航 -->
    <el-breadcrumb separator-class="el-icon-arrow-right" class="margin-t10">
      <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>充值管理</el-breadcrumb-item>
    </el-breadcrumb>
    <div class="boxBlock"> 
      <div class="serachTop"> 
          <!-- 搜索筛选 -->
          <el-form :inline="true" :model="formInline" class="user-search">
            <el-form-item  >
              <el-select
                size="small"
                v-model="formInline.status"
                placeholder="请选择审核状态"
                clearable
              >
                <el-option label="请选择审核状态" value=""></el-option>
                <el-option
                  v-for="type in statusData"
                  :label="type.key"
                  :value="type.value"
                  :key="type.value"
                ></el-option>
              </el-select>
            </el-form-item>

            <el-form-item>
              <el-button
                size="small"
                type="primary"
                icon="el-icon-search"
                @click="search"
                >搜索</el-button
              >
            </el-form-item>
          </el-form>
          <el-button size="small" type="primary" icon="el-icon-download" @click="exportEx()">
            导出
          </el-button>
      </div>
    
  
    <!--列表-->
    <div class="ra_box"> 
      <el-table
        size="small"
        :data="listData"
        highlight-current-row
        v-loading="loading"
        element-loading-text="拼命加载中"
        style="width: 100%"
        v-if="listData"
      >
        <el-table-column
          prop="userId"
          label="用户ID"
          show-overflow-tooltip
          width="80"
        >
        </el-table-column>
        <el-table-column
          prop="updateBy"
          label="操作人"
          show-overflow-tooltip
          width="120"
        >
        </el-table-column>
        
        <el-table-column prop="orderNo" label="订单编号" show-overflow-tooltip>
        </el-table-column>
        <el-table-column prop="usd" label="充值金额" show-overflow-tooltip>
          <template slot-scope="scope">
            {{ b(scope.row.usd) }}
          </template>
        </el-table-column>
        <el-table-column prop="amount" label="到账金额" show-overflow-tooltip>
          <template slot-scope="scope">
            {{ b(scope.row.amount) }}
          </template>
        </el-table-column>
        <el-table-column
          prop="createTime"
          label="充值时间"
          show-overflow-tooltip
        >
          <template slot-scope="scope">
            {{ timestampToTime(scope.row.createTime) }}
          </template>
        </el-table-column>
        <el-table-column prop="status" label="审核状态" show-overflow-tooltip>
          <template slot-scope="scope">
            {{ statusData[scope.row.status].key }}
          </template>
        </el-table-column>
        <el-table-column align="center" label="操作" width="150">
          <template slot-scope="scope">
            <el-button type="success" plain size="mini"
              @click="checkUser(scope.$index, scope.row)" 
              v-if="scope.row.status == '0'" 
            >
            审核
              
            </el-button>
            <el-button
             size="mini" plain
              v-else
              
              @click="checkUser(scope.$index, scope.row)" 
            >
               查看 
            </el-button>
            
          </template>
        </el-table-column>
      </el-table>
    </div>
    <!-- 分页组件 -->
    <Pagination
      v-bind:child-msg="pageparm"
      @callFather="callFather"
    ></Pagination>
  </div>
    <!-- 审核界面 -->
    <el-dialog
      title="查看详情"
      :close-on-click-modal="false"
      :visible.sync="editFormVisible"
      width="50%"
      @close="closeDialog"
      v-if="editForm"
    >
      <el-form :model="editForm" :rules="rules" ref="editForm">
        <el-row :gutter="20">
          <el-col :span="12">
            <el-form-item label="用户ID" prop="userId">
              {{ editForm.userId }}
            </el-form-item>
            <el-form-item label="充值单号" prop="orderNo">
              {{ editForm.orderNo }}
            </el-form-item>

            <el-form-item label="收款金额" prop="usd">
              {{ editForm.usd }}
            </el-form-item>
            <el-form-item label="充值时间" prop="createTime">
              {{ timestampToTime(editForm.createTime) }}
            </el-form-item>
            <el-form-item
              label="充值凭证"
              prop="receipt"
              v-if="editForm.receipt"
            >
              <el-image
                v-if="editForm.receipt"
                :src="baseURL + `/profile` + editForm.receipt.fileStoragePath"
                :preview-src-list="[
                  baseURL + `/profile` + editForm.receipt.fileStoragePath,
                ]"
              ></el-image>
            </el-form-item>
            <el-form-item label="充值备注" prop="remark">
              {{ editForm.remark }}
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="审核状态" prop="status">
              {{ statusData[editForm.status].key }}
            </el-form-item>
            <el-form-item label="到账金额" prop="amount">
              <el-input
                size="small"
                v-model="editForm.amount"
                auto-complete="off"
                placeholder="请输入到账金额xxx"
              ></el-input>
            </el-form-item>
            <el-form-item label="审核备注" prop="auditResult">
              <el-input
                size="small"
                v-model.trim="editForm.auditResult"
                auto-complete="off"
                type="textarea"
                :rows="5"
                placeholder="请输入备注"
              ></el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>

      <div slot="footer" class="dialog-footer">
        <el-button
          type="primary"
          :disabled="disabled"
          @click="submitForm(1)"
          v-if="editForm.status == 0"
        >
          通过
        </el-button>
        <el-button
          type="danger"
          :disabled="disabled"
          @click="submitForm(2)"
          v-if="editForm.status == 0"
        >
          驳回
        </el-button>
      </div>
    </el-dialog>
    <codeChoose ref="codeRef" :fromType="verType" @setParam="getParam" ></codeChoose>
  </div>
</template>

<script>
import { mapState, mapGetters } from "vuex";
import codeChoose from '@/components/codeChoose.vue'
import {
  setStoreS,
  getStoreS,
  removeStoreS,
  insertCharacter,
  timestampToTime,
  spStr,
} from "../../utils/util";
import {
  baseURL,
  req,
  reqJson,
  service,
  encrypt,
  decrypt,
  reqtoken,
  reqField,
  format,
  getUrl, 
} from "../../api/axiosFun";
import Pagination from "../../components/Pagination";
export default {
  data() {
    return {
      loading: false,
      editFormVisible: false,
      title: "添加",
      b: format,
      timestampToTime: timestampToTime,
      baseURL: baseURL,
      disabled: false,
      statusData: [
        { key: "待审核", value: 0 },
        { key: "通过", value: 1 },
        { key: "驳回", value: 2 },
      ],
      editForm: "",
      rules: {
        amount: [
          { required: true, message: "充值金额", trigger: "blur" },
          {
            pattern: /^[0-9]+(\.\d{1,2})?$/,
            message: "请输入正整数或者2位数小数",
            trigger: "blur",
          },
        ],
      },
      formInline: {
        pageNum: 1,
        pageSize: 10,
        status: "",
        userId: "",
      },
      listData: [],
      // 分页参数
      pageparm: {
        currentPage: 1,
        pageSize: 10,
        total: 10,
      },
      verArry:[],
      verType:'',
      curItem:'', 
      userInfo: null,
      fd:''
    };
  },
  components: {
    Pagination,
    codeChoose
  },
  created() {
    this.getdata(this.formInline);
    this.getInfo();
  },
  methods: { 
    getInfo() {
      service
        .get("/api/photon/getUserInfo", {})
        .then((res) => {
          this.loading = false;
          if (res.code == 0) {
            this.userInfo = res.data;
            this.$store.commit("user", JSON.stringify(res.data));
          } else {
            this.$message({
              type: "info",
              message: spStr(res.msg, "PhotonPay", ""),
            });
          }
        })
        .catch((err) => {
          this.$message.error(err);
        });
    },    
    exportEx() {
      let url = getUrl(this.formInline);
      service
        .post("/api/admin/exportRechargeRecordList" + url, {})
        .then((res) => {
          this.loading = false; 
          if (res.code == 0) {
            window.open(
              baseURL + "/common/download?fileName=" + res.msg,
              "_blank"
            );
          } else {
            this.$message({
              type: "info",
              message: spStr(res.msg, "PhotonPay", ""),
            });
          }
        })
        .catch((err) => {
          this.loading = false;
          this.$message.error(spStr(err, "PhotonPay", ""));
        });
    },
    getdata(parameter) {
      let url = getUrl(parameter);
      service
        .get("/api/admin/getRechargeRecordList" + url, {})
        .then((res) => {
          this.loading = false;
          if (res.code == 0) {
            this.listData = res.rows; 
            this.pageparm.currentPage = this.formInline.pageNum;
            this.pageparm.pageSize = this.formInline.pageSize;
            this.pageparm.total = res.total;
          } else {
            this.$message({
              type: "info",
              message: spStr(res.msg, "PhotonPay", ""),
            });
          }
        })
        .catch((err) => {
          this.loading = false;
          this.$message.error(spStr(err, "PhotonPay", ""));
        });
    },
    callFather(parm) {
      console.log(parm);
      this.formInline.pageNum = parm.currentPage;
      this.formInline.pageSize = parm.pageSize;
      this.getdata(this.formInline);
    },
    // 搜索事件
    search() {
      this.getdata(this.formInline);
    },
    checkUser(index, row) {
      this.editFormVisible = true;
      this.editForm = row;
    },
    getParam(val,type){  
      this.headers = val ;
      this.editSaveAuth() 
    },  
    editSaveAuth(){ 
      let parm = {
            id: this.editForm.id,
            orderNo: this.editForm.orderNo,
            rechargeAmount: this.editForm.amount,
            remark: this.editForm.auditResult,
            status: this.fn,
            userId: this.editForm.userId,
       },
       url = getUrl(parm); 
        reqJson('post',"/api/admin/verifyRecharge" + url, {},{
          headers:{
            ...this.headers
          }
        }) 
        .then((res) => {
          this.disabled = false;
          if (res.code == 0) {
            this.$message.success("提交成功");
            this.getdata(this.formInline);
            this.closeDialog();
          } else {
            this.$message({
              type: "info",
              message: spStr(res.msg, "PhotonPay", ""),
            });
          }
        })
        .catch((err) => {
          this.$message.error(spStr(err, "PhotonPay", ""));
        });
    },
    submitForm(type) {
      this.$refs.editForm.validate((valid) => {
        if (!valid) return;
        this.disabled = true;
        this.fn = type;
        if(this.userInfo&&this.userInfo.verifyApi){
            this.verArry =  this.userInfo.verifyApi.split(',');
          if(this.verArry.includes('/api/admin/verifyRecharge')){
            this.$refs.codeRef.openDialog(); 
          }else{
            this.editSaveAuth();
          }
        }else{
          this.editSaveAuth();
        }
         
      });
    },
    // 关闭编辑、增加弹出框
    closeDialog() {
      this.editFormVisible = false;
    },
  },
};
</script>

<style scoped>
.user-search {
  margin-top: 20px;
}
.el-upload .avatar {
  margin-left: -15px;
  margin-top: -15px;
  width: 180px;
  height: 180px;
  display: block;
}
.el-image {
  width: 180px;
  height: 180px;
}
</style>

 
 